package com.woniu.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.entity.FlowerOrder;
import com.woniu.service.FlowerOrderService;
import com.woniu.util.JsonResult;
import com.woniu.vo.FlowerOrderVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @program:
 * @ClassName:
 * @description:
 * @author: zgc
 * @date:
 * @Version 1.0
 **/
@RestController
@RequestMapping("/flowerorder")
public class FlowerOrderController {
    @Resource
    private FlowerOrderService flowerOrderService;
    // 查询所有订单
    @RequestMapping("/selectFlowerOrderByMerchant")
    public JsonResult<PageInfo<FlowerOrderVo>> selectFlowerOrderByMerchant
    (Integer pageNum, Integer pageSize, String orderId, String accountName,Integer status, Long startTime,Long endTime) {
        PageInfo<FlowerOrderVo> list = flowerOrderService.selectFlowerOrderByMerchant(pageNum,pageSize,orderId,accountName,status,startTime,endTime);
      
        return JsonResult.ok(200, list);
    }
    
    //查看订单详情
    @RequestMapping("/selectFlowerOrderByOrderId")
    public JsonResult<FlowerOrderVo> selectFlowerOrderByOrderId(String orderId) {
        FlowerOrderVo flowerOrderVo = flowerOrderService.selectFlowerOrderByOrderId(orderId);
        
        return JsonResult.build(200, "查看成功", flowerOrderVo);
    }
    
    //修改订单状态详情
    @RequestMapping("/updateFlowerOrderStatusByOrderId")
    public JsonResult<Integer> updateFlowerOrderStatusByOrderId(Long orderId, Byte status) {
        FlowerOrder flowerOrder = new FlowerOrder(orderId,status);
        int i = flowerOrderService.updateFlowerOrderStatusByOrderId(flowerOrder);
        return JsonResult.build(200, "提交成功", i);
    }
    
    //查询最新订单
    @RequestMapping("/selectNewFlowerOrder")
    public JsonResult<PageInfo<FlowerOrderVo>> selectNewFlowerOrder(Integer pageNum, Integer pageSize) {
        PageInfo<FlowerOrderVo> list = flowerOrderService.selectNewFlowerOrder(pageNum,pageSize);
        return JsonResult.build(200, "查询成功", list);
    }
    
    //查询当天的销售额
    @RequestMapping("/selectDayTotal")
    public JsonResult<FlowerOrderVo> selectDayTotal() {
        FlowerOrderVo dayTotal = flowerOrderService.selectDayTotal();
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-mm-dd HH:mm:ss");
        dayTotal.setNowTime(now.format(formatter));
        return JsonResult.build(200, "查询成功", dayTotal);
    }
    
    //查询本周的销售额
    @RequestMapping("/selectWeekTotal")
    public JsonResult<FlowerOrderVo> selectWeekTotal() {
        FlowerOrderVo weekTotal = flowerOrderService.selectWeekTotal();
        return JsonResult.build(200, "查询成功", weekTotal);
    }
    
    //查询本月的销售额
    @RequestMapping("/selectMonthTotal")
    public JsonResult<FlowerOrderVo> selectMonthTotal() {
        FlowerOrderVo monthTotal = flowerOrderService.selectMonthTotal();
        return JsonResult.build(200, "查询成功", monthTotal);
    }
    
    //查询今年的销售额
    @RequestMapping("/selectYearTotal")
    public JsonResult<FlowerOrderVo> selectYearTotal() {
        FlowerOrderVo yearTotal = flowerOrderService.selectYearTotal();
        return JsonResult.build(200, "查询成功", yearTotal);
    }
    
    //查询总的销售额
    @RequestMapping("/selectAllTotal")
    public JsonResult<FlowerOrderVo> selectAllTotal() {
        FlowerOrderVo allTotal = flowerOrderService.selectAllTotal();
        return JsonResult.build(200, "查询成功", allTotal);
    }
}
